﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbMovieKeywordsTest and is intended
    ///     to contain all TmdbMovieKeywordsTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbMovieKeywordsTest
    {
        /// <summary>
        ///     A test for TmdbMovieKeywords Constructor
        /// </summary>
        [TestMethod]
        public void TmdbMovieKeywordsConstructorTest()
        {
            var target = new TmdbMovieKeywords();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbMovieKeywords();
            int expected = new Random().Next( 0, Int32.MaxValue );
            int actual;
            target.Id = expected;
            actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Keywords
        /// </summary>
        [TestMethod]
        public void KeywordsTest()
        {
            var target = new TmdbMovieKeywords();
            var expected = new List<TmdbKeyword>();
            List<TmdbKeyword> actual;
            target.Keywords = expected;
            actual = target.Keywords;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\movieKeywords.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbMovieKeywords();
            var jsonContent = File.ReadAllText( "movieKeywords.json.txt" );
            var actual = await target.DeserializeJson<TmdbMovieKeywords>( jsonContent );

            Assert.AreEqual( 550, actual.Id );
            Assert.AreEqual( 5, actual.Keywords.Count );

            Assert.AreEqual( 397, actual.Keywords[ 0 ].Id );
            Assert.AreEqual( "bare knuckle boxing", actual.Keywords[ 0 ].Name );

            Assert.AreEqual( 825, actual.Keywords[ 1 ].Id );
            Assert.AreEqual( "support group", actual.Keywords[ 1 ].Name );

            Assert.AreEqual( 1541, actual.Keywords[ 2 ].Id );
            Assert.AreEqual( "nihilism", actual.Keywords[ 2 ].Name );

            Assert.AreEqual( 3848, actual.Keywords[ 3 ].Id );
            Assert.AreEqual( "support", actual.Keywords[ 3 ].Name );

            Assert.AreEqual( 17977, actual.Keywords[ 4 ].Id );
            Assert.AreEqual( "underground fighting", actual.Keywords[ 4 ].Name );
        }
    }
}